package com.xyw.code.platform.webapps.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xyw.code.platform.common.entity.po.SysMenu;
import com.xyw.code.platform.common.entity.po.SysRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 系统角色表 Mapper 接口
 * </p>
 *
 * @author xyw
 * @since 2020-02-07
 */
@Mapper
public interface SysRoleMapper extends BaseMapper<SysRole> {

    /**
     * 通过用户ID，查询角色信息
     *
     * @param userId
     * @return
     */
    @Select("SELECT r.* FROM sys_role r, sys_user_role ur WHERE r.id = ur.role_id AND r.del_flag = 0 and  ur.user_id IN (#{userId})")
    List<SysRole> listRolesByUserId(Long userId);

    /**
     * 根据角色得到菜单
     * @param roleId
     * @return
     */
    @Select("select m.id,m.name,m.type,m.parent_id,m.sort,m.perms from sys_menu m, sys_role_menu rm where rm.role_id = #{roleId} and m.id = rm.menu_id")
    List<SysMenu> findMenuListByRoleId(Long roleId);

    List<SysRole> query(SysRole role);
}
